package lsl.leetCode.year2023.test0303;

/**
 * description:
 *
 * @author: liushengli
 * data: 2023/3/3
 */
public class test434 {
    public static void main(String[] args) {
        String s = "Hello, my name is John";
        System.out.println(countSegments(s));
    }

    public static int countSegments(String s) {
        char[] charArray = s.toCharArray();
        int num = 0;
        for (int i = 0; i < charArray.length; i++) {
            if ((i == 0 || charArray[i - 1] == ' ') && ' ' != charArray[i]) {
                num++;
            }
        }
        return num;
    }
}
